import 'dart:ffi';

import 'package:flutter/material.dart';
import 'package:my_app_01/config.dart';
import 'package:nil/nil.dart';

class ListItemCard extends StatelessWidget {
  final Widget? title;

  final List<Widget>? children;
  final List? childrenProps;
  final dynamic data;

  final IconData? icon;

  final Widget? right;

  void Function()? onTap;

  static const TextStyle defaultTitleStyle =
      TextStyle(fontSize: 18, color: Colors.black87, fontWeight: FontWeight.w600);

  static TextStyle defaultLabelStyle = TextStyle(fontSize: 14, color: MyConfig.color_666);
  static TextStyle defaultContentStyle = TextStyle(fontSize: 14, color: MyConfig.color_333);

  ListItemCard(
      {super.key, this.title, this.icon, this.right, this.onTap, this.data, this.children, this.childrenProps});

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: onTap,
      child: Card(
        margin: const EdgeInsets.only(top: 15),
        color: Colors.white,
        surfaceTintColor: Colors.white,
        elevation: 6,
        shadowColor: Colors.black12,
        clipBehavior: Clip.hardEdge,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(8),
        ),
        child: Container(
          padding: const EdgeInsets.only(top: 15, right: 15, bottom: 10, left: 15),
          child: Column(
            children: [
              title != null
                  ? Container(
                      alignment: Alignment.centerLeft,
                      padding: const EdgeInsets.only(bottom: 5),
                      margin: const EdgeInsets.only(bottom: 5),
                      decoration: const BoxDecoration(
                        border: Border(
                          bottom: BorderSide(
                            color: Colors.black12,
                            width: 1,
                          ),
                        ),
                      ),
                      child: title,
                    )
                  : nil,
              Column(
                children: children != null
                    ? children!
                    : childrenProps!.asMap().entries.map((e) {
                        return Container(
                          margin: const EdgeInsets.only(bottom: 4),
                          child: Row(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              SizedBox(
                                width: 80,
                                child: Text(
                                  "${e.value['label']}：",
                                  style: defaultLabelStyle,
                                ),
                              ),
                              Expanded(
                                flex: 1,
                                child: Text(
                                  "${e.value['value']}",
                                  style: defaultContentStyle,
                                  maxLines: 2,
                                  overflow: TextOverflow.ellipsis,
                                ),
                              )
                            ],
                          ),
                        );
                      }).toList(),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
